package com.kodak.collin;

import java.util.regex.Pattern;


import com.mongodb.*;




public class Main {

	public static void main(String[] args) throws Exception{	

		 
		Mongo m = new Mongo("localhost",27017);
		DB db = m.getDB("medical");
		DBCollection coll = db.getCollection("document");
		/*
		for(int i=0;i<100000;i++){
			DBObject dbObject = (DBObject)Util.xml2DBObject("E:\\cda\\cda"+i+".xml");
			coll.insert(dbObject);
		}
		
		*/
		System.out.println(coll.getCount());
		/*
		DBCursor cursor = coll.find();
		
		while(cursor.hasNext()){
			DBObject dbObject = cursor.next();
			//Util.convertString2XML(dbObject.get("content").toString(),"E:\\cda\\result\\cda"+ count++ +".xml");
			//System.out.println(dbObject.toString());
			
		}
		cursor.close();
		System.out.println("===================================");
		//DBObject queryAddress = new BasicDBObject("ClinicalDocument.recordTarget.patientRole.addr.state","湖南省");
		*/
		long beginTime= System.currentTimeMillis();
		
		DBObject queryAddress = new BasicDBObject("ClinicalDocument.recordTarget.patientRole.addr.city","株洲市");
		DBCursor addCursor = coll.find(queryAddress);
		int countChangsha = addCursor.count();
		
//		while(addCursor.hasNext()){
//			//System.out.println(addCursor.next());
//			addCursor.next();
//		}
		addCursor.close();
		
		long afterTime= System.currentTimeMillis();
		System.out.println("Result set is "+countChangsha+".");
		System.out.println("Time consumed while quiring is "+ (afterTime - beginTime) +" millionseconds.");
		
		System.out.println("===================================");
		Pattern changsha = Pattern.compile("^.*洲.*$", Pattern.CASE_INSENSITIVE);
		DBObject regexQuery = new BasicDBObject("ClinicalDocument.recordTarget.patientRole.addr.city", changsha);
		long changshaBegin = System.currentTimeMillis();
		DBCursor changshaCursor = coll.find(regexQuery);
		int countRegex = changshaCursor.count();
		
		changshaCursor.close();
		long changshaAfter = System.currentTimeMillis();
		System.out.println("Result set is "+countRegex+".");
		System.out.println("Time consumed while quiring is "+ (changshaAfter - changshaBegin) +" millionseconds.");

		
	}
	
	
	
}